package com.gigi.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.gigi.model.*;
import com.gigi.service.manual.CourseManageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 课程管理
 */
@RestController
@RequestMapping("course-manage")
public class CourseManageController {

    private final CourseManageService courseManageService;

    public CourseManageController(CourseManageService courseManageService) {
        this.courseManageService = courseManageService;
    }

    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public Response save(@RequestBody @Valid CourseDO request) {
        return courseManageService.save(request);
    }

    @ApiOperation(value = "详情")
    @PostMapping("/detail")
    public SingleResponse<CourseDO> detail(@RequestBody @Valid IdRequest request) {
        return courseManageService.detail(request);
    }

    @ApiOperation(value = "切换有效性")
    @PostMapping("/switch-flag")
    public Response switchFlag(@RequestBody @Valid IdRequest request) {
        return courseManageService.switchFlag(request.getId());
    }

    @ApiOperation(value = "老师课程列表")
    @PostMapping("/list-by-teacher")
    public MultiResponse<CourseDO> listByTeacher(@RequestBody @Valid ListCourseRequest request) {
        return courseManageService.listByTeacher(request);
    }

    @ApiOperation(value = "学生课程列表")
    @PostMapping("/list-by-student")
    public MultiResponse<StudentCourseDO> listByStudent(@RequestBody @Valid ListCourseRequest request) {
        return courseManageService.listByStudent(request);
    }

    @ApiOperation(value = "搜索课程")
    @PostMapping("/search")
    public SingleResponse<CourseDO> search(@RequestBody @Valid SearchCourseRequest request) {
        return courseManageService.search(request);
    }

    @ApiOperation(value = "课程成员列表")
    @PostMapping("/member")
    public SingleResponse<CourseMemberDO> member(@RequestBody @Valid ListCourseMemberRequest request) {
        return courseManageService.member(request);
    }

}
